package com.ruibang.glass.equipment.service.impl.device;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruibang.glass.equipment.domain.req.device.BoilerInfoPageReq;
import com.ruibang.glass.equipment.entity.device.BoilerInfo;
import com.ruibang.glass.equipment.mapper.device.BoilerInfoMapper;
import com.ruibang.glass.equipment.service.BoilerInfoService;
import com.teaming.cloud.framework2.common.model.ResultBody;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * <p>
 *获取锅炉列表服务类
 * </p>
 *
 * @author mameng
 * @since 2024-03-20
 */
@Slf4j
@Service
public class BoilerInfoServiceImpl extends ServiceImpl<BoilerInfoMapper, BoilerInfo> implements BoilerInfoService {

    /**
     * 获取锅炉列表
     * @param boilerInfo
     * @return
     */
    @Override
    public IPage<BoilerInfo> queryBoilerList(BoilerInfoPageReq boilerInfo) {
        IPage<BoilerInfo> boilerInfoIPage = baseMapper.queryBoilerInfo(new Page<>(boilerInfo.getPageNo(), boilerInfo.getPageSize()), boilerInfo);
        return boilerInfoIPage;
    }

    /**
     * 更新
     * @param boilerInfo
     * @return
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public ResultBody updateOrAddById(BoilerInfo boilerInfo) {
        if (StringUtils.isBlank(boilerInfo.getId())){
            baseMapper.insert(boilerInfo);
            return ResultBody.success();
        }
        baseMapper.updateById(boilerInfo);
        return ResultBody.success();
    }
}
